import { useContext } from 'react';
import { useMemoizedFn } from 'ahooks';
import Entypo from '@expo/vector-icons/Entypo';
import FontAwesome6 from '@expo/vector-icons/FontAwesome6';
import { Modal, message } from '@/components';
import { MoreMenuContext } from './context';
import type { MenuItemType } from './types';

export const useDatas = () => {
  return useContext(MoreMenuContext);
}

export const useItems = () => {
  const { items = [] } = useDatas();

  const handleBlock = useMemoizedFn(async () => {
    Modal.confirm({
      danger: true,
      okText: 'Block',
      title: 'Block account?',
      content: 'Blocked accounts cannot reply in your threads, mention you, or otherwise interact with you.',
      onOk: () => {
        message.success('Blocked account successfully.');
        return true;
      }
    });
    return true;
  });

  const handleReport = useMemoizedFn(async () => {
    return true;
  });

  const defaultItems: MenuItemType[] = [
    {
      key: 'block',
      title: 'Block',
      onPress: handleBlock,
      icon: <FontAwesome6 name="user-xmark" />
    },
    {
      key: 'report',
      title: 'Report',
      onPress: handleReport,
      icon: <Entypo name="warning" />
    }
  ];

  return [...items, ...defaultItems];
}
